const path = require('path');
const cors = require('koa2-cors');
const Koa = require('koa');
const koaBody = require('koa-body');
const KoaStatic = require('koa-static');
const router = require('../router');
const errorHandler = require('./errHandler');
const parameter = require('koa-parameter')
const {accessLogger} = require('../config/config.logConfig')
const app = new Koa();
app.use(
  cors()
);
app.use(koaBody({multipart:true,formidable:{
  //在配置选项option里面不推荐使用相对路径
  //在option里面的相对路径，不是相对的当前文件
  uploadDir:path.join(__dirname,'../uploads'),
  keepExtensions:true,}}));


app.use(KoaStatic(path.join(__dirname,'../uploads'),))

app.use(parameter(app));
app.use(accessLogger());
app.use(router.routes()).use(router.allowedMethods());

app.on('error',errorHandler);

module.exports = app;
